import axios from 'axios';
import { useTokenStore } from '@/stores/token'; // 根据你的路径调整

const API_BASE_URL = '/api/teacher'; // 使用代理路径

const getAuthHeaders = () => {
    const tokenStore = useTokenStore();
    return {
        Authorization: ` ${tokenStore.token}`
    };
};

// 教师完善信息
export const improveTeacherInfo = async (teacherName) => {
    try {
        const response = await axios.post(`${API_BASE_URL}/improve`, { teacherName }, {
            headers: getAuthHeaders()
        });
        return response.data;
    } catch (error) {
        console.error('Error improving teacher info:', error.response?.data || error.message);
        throw new Error('Error improving teacher info');
    }
};

// 教师修改个人信息
export const updateTeacherInfo = async (data) => {
    try {
        const response = await axios.put(`${API_BASE_URL}/update`, data, {
            headers: getAuthHeaders()
        });
        return response.data;
    } catch (error) {
        console.error('Error updating teacher info:', error.response?.data || error.message);
        throw new Error('Error updating teacher info');
    }
};
